package com.lft.com.oilgas.controller;


import com.lft.com.oilgas.entity.Admin;
import com.lft.com.oilgas.entity.Driver;
import com.lft.com.oilgas.service.impl.DriverServiceImpl;
import com.lft.com.oilgas.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tyqw
 * @since 2024-09-10
 */
@RestController
@CrossOrigin
@RestControllerAdvice
@RequestMapping("/util/driver")
public class DriverController {
    @Autowired
    private DriverServiceImpl driverServiceImpl;
    //处理异常
    @ExceptionHandler(Exception.class)
    private Result yichang(Exception e){
        //noinspection CallToPrintStackTrace
        e.printStackTrace();
        return new Result(false,"服务器异常，请稍后重试");
    }
    @Transactional
    @RequestMapping("/getDriver")
    public Result getDriver() {
        return new Result(true,driverServiceImpl.getDriver());
    }
    @Transactional
    @RequestMapping("/insertAndUpdateDriver")
    public Result getDriver(@RequestBody Driver driver) {
        System.out.println(driver);
        return new Result(true,driverServiceImpl.insertAndUpdateDriver(driver));
    }


}
